package com.rop.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rop.model.system.SysOperLog;
import com.rop.model.vo.SysOperaLogQueryVo;
import com.rop.system.mapper.SysOperateLogMapper;
import com.rop.system.service.AsyncOperationLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Title: SysOperateLogServiceImpl
 * @Author Rop
 * @Date 2023/5/16 15:53
 * @description: 操作日志
 */

@Service
public class SysOperateLogServiceImpl extends ServiceImpl<SysOperateLogMapper, SysOperLog> implements AsyncOperationLogService {

    @Autowired
    private SysOperateLogMapper sysOperateLogMapper;

    @Override
    public void saveLog(SysOperLog sysOperLog) {
        sysOperateLogMapper.insert(sysOperLog);
    }

    /**
     * 分页列表查询
     * @param page ""
     * @param limit ""
     * @param sysOperaLogQueryVo ""
     * @return ""
     */
    @Override
    public IPage<SysOperLog> selectPage(Long page, Long limit, SysOperaLogQueryVo sysOperaLogQueryVo) {
        Page<SysOperLog> logPage = new Page<>(page,limit);

        QueryWrapper<SysOperLog> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(sysOperaLogQueryVo.getOperName())) {
            queryWrapper.like("oper_name", sysOperaLogQueryVo.getOperName());
        }

        if (StringUtils.isNotBlank(sysOperaLogQueryVo.getTitle())) {
            queryWrapper.like("title", sysOperaLogQueryVo.getTitle());
        }

        if (StringUtils.isNotBlank(sysOperaLogQueryVo.getCreateTimeBegin())) {
            queryWrapper.ge("create_time", sysOperaLogQueryVo.getCreateTimeBegin());
        }

        if (StringUtils.isNotBlank(sysOperaLogQueryVo.getCreateTimeEnd())) {
            queryWrapper.le("create_time", sysOperaLogQueryVo.getCreateTimeEnd());
        }

        return baseMapper.selectPage(logPage, queryWrapper);
    }
}
